<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="js/jquery-3.2.1.js"></script>
    
    <style>
        body{
            height: 2000px;
            background-color: #333;
        }
        .nav{
            width: 100px;
            height: 100px;
            background-color: red;
            opacity: 0;
            position: fixed;
            right: 20px;
            bottom: 30px;
        }
    </style>
</head>
<body>
    <div class="nav">
        
    </div>

    <script>
        $(window).scroll(function(){
            let scrollTop = $(window).scrollTop();
            let opacity;
            console.log(scrollTop);
            opacity = scrollTop/200;

            if(scrollTop>=200){
            opacity=1;
        }
        
        $(".nav").css({opacity:opacity});
        }) 
        $(".nav").click(function(){
            $("html").animate({scrollTop:"0px"},1000);
        })
    </script>
    
</body>
</html>